﻿/*****************************************************************//**
 * @file    FITKAcousticsVTKGraphObjectPart.h
 * @brief   Graph object for part of the FE-model data.
 *  
 * @author  ChengHaotian (yeguangbaozi@foxmail.com)
 * @date    2024-10-28
 *********************************************************************/

#ifndef __FITKACOUSTICSVTKGRAPHOBJECTPART_H__
#define __FITKACOUSTICSVTKGRAPHOBJECTPART_H__

#include "FITKAcousticsVTKGraphObject3D.h"

#include "FITKAcousticsVTKGraphAdaptorAPI.h"

// Forward declaration
class FITKAcousticsVTKGraphActor;
class FITKHighOrderCellFilter;

namespace Interface
{
    class FITKMeshFeatureVTK;
    class FITKAbaMeshPartVTK;
    class FITKModelSet;
}

namespace AbaqusData
{
    class FITKAbaqusPart;
}

namespace Exchange
{
    class FITKAcousticsVTKColorMap;
    class FITKAcousticsVTKGraphObjectSelect;
}

namespace Exchange
{
    /**
     * @brief   Graph object for 'part'.
     * @author  ChengHaotian (yeguangbaozi@foxmail.com)
     * @date    2024-10-28
     */
    class FITKACOUSTICSGRAPHADAPTORAPI FITKAcousticsVTKGraphObjectPart : public FITKAcousticsVTKGraphObject3D
    {
        /**
         * @brief   The color mode enum.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-30
         */
        enum ColorMode
        {
            ColorDefault = 0,
            ColorSection = 2,
            ColorMaterial = 3
        };

        // Regist
        FITKGraphObjectRegist(FITKAcousticsVTKGraphObjectPart, FITKAcousticsVTKGraphObject3D);
        FITKCLASS(Exchange, FITKAcousticsVTKGraphObjectPart);

    public:
        /**
         * @brief   Constructor.
         * @param   part: The FE-model part data.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-28
         */
        FITKAcousticsVTKGraphObjectPart(AbaqusData::FITKAbaqusPart* part);

        /**
         * @brief   Destructor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-28
         */
        ~FITKAcousticsVTKGraphObjectPart() = default;

        /**
         * @brief   Update all graph actors.[override]
         * @param   forceUpdate: Force update[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-30
         */
        void update(bool forceUpdate = false) override;

        /**
         * @brief   Update the visibility with data object's visibility.[override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-12
         */
        void updateVisibility() override;

        /**
         * @brief   Show or hide graph object.[override]
         * @param   visibility: The visibility of graph object
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-12
         */
        void setVisible(bool visibility) override;

        /**
         * @brief   Set the graph actors to the default color.[virtual]
         * @param   forceUpdate: Force update the color mode
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-30
         */
        void colorByDefault(bool forceUpdate = false);

        /**
         * @brief   Set the graph actors with the material's color.[virtual]
         * @param   forceUpdate: Force update the color mode
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-30
         */
        void colorByMaterial(bool forceUpdate = false);

        /**
         * @brief   Set the graph actors with the section's color.[virtual]
         * @param   forceUpdate: Force update the color mode
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-30
         */
        void colorBySection(bool forceUpdate = false);
        /**
         * @brief    每个单元中添加对应的sectionID
         * @author   BaGuijun (baguijun@163.com)
         * @date     2025-01-02
         */
        void idBySection();
        /**
         * @brief   Enable or disable transparent.[override]
         * @param   isOn: Enable or disable
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-09
         */
        void setTransparent(bool isOn) override;

        /**
         * @brief   Highlight the graph actors.[override]
         * @param   type: The shape type need to be highlighted[default]
         * @param   color: The given color for highlighting this time[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-31
         */
        void highlight(FITKAcousticsVTKCommons::ShapeType type = FITKAcousticsVTKCommons::ShapeTypeNone, QColor color = QColor()) override;

        /**
         * @brief   Dis-highlight the graph actors.[override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-31
         */
        void disHighlight() override;

        /**
         * @brief   Advanced highlight mode for highlighting part of the graph actors.[override]
         * @param   type: The type of the model need to be highlighted
         * @param   indice: The given indice of the model component need to be highlight
         * @param   color: The given color for highlighting this time[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-31
         */
        void advanceHighlight(FITKAcousticsVTKCommons::ShapeType type, QVector<int> indice, QColor color = QColor()) override;

        /**
         * @brief   Dis-highlight the graph actors if the graph object is in advanced highlighting mode.[override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-31
         */
        void disAdvanceHighlight() override;

        /**
         * @brief   Set if the graph object pickable mode.[override]
         * @param   mode: The pickable mode
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-31
         */
        void setPickMode(FITKAcousticsVTKCommons::ShapePickMode mode) override;

        /**
         * @brief   Get the shape id by the given shape type and VTK cell id.[override]
         * @param   vtkId: The VTK point or cell id in shape data
         * @param   topAbsShapeType: The shape type of the given ID( the same as TopAbs_ShapeEnum )
         * @return  The shape id
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-01
         */
        int getShapeIdByVTKCellId(int vtkId, FITKAcousticsVTKCommons::ShapeMeshAbsEnum topAbsShapeType) override;

        /**
         * @brief   Get the VTK point or cell indice by the given shape type and shape id.[override]
         * @param   shapeId: The shape id in shape data
         * @param   topAbsShapeType: The shape type of the given ID( the same as TopAbs_ShapeEnum )
         * @return  The cell indice[const]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-01
         */
        const QVector<int> getVTKCellIdsByShapeId(int shapeId, FITKAcousticsVTKCommons::ShapeMeshAbsEnum topAbsShapeType) override;

        /**
         * @brief   Get the VTK mesh grid by the given mesh type.[override]
         * @param   type: The shape's VTK mesh type
         * @return  The vtkDataSet object of the given type of mesh
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-31
         */
        vtkDataSet* getMesh(FITKAcousticsVTKCommons::ShapeType type) override;

        /**
         * @brief   Test function - Write out the mesh file to the given file path( The variant value ).
         * @param   v: The file path
         * @return  Is the file written
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-04
         */
        bool test(QVariant & v) override;

    private:
        /**
         * @brief   Get set's ids for custom type and generated type.
         * @param   set: The set data
         * @param   Indice: The indice of set members[quote]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-30
         */
        void getSetIds(Interface::FITKModelSet* set, QList<int> & indice);

        /**
         * @brief   Generate the actor with the part data.
         * @param   part: The part data
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-28
         */
        void generateGraph(AbaqusData::FITKAbaqusPart* part);

    private:
        /**
         * @brief   The color map key words for showing default model color.[const]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-30
         */
        const QString c_defaultArrName = "Default";

        /**
         * @brief   The color map key words for showing materials color.[const]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-30
         */
        const QString c_materialArrName = "Materials";

        /**
         * @brief   The color map key words for showing sections color.[const]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-30
         */
        const QString c_sectionArrName = "Sections";

        /**
         * @brief   The model extractor for normal or advanced highlight.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-31
         */
        FITKAcousticsVTKGraphObjectSelect* m_highlightSelector{ nullptr };

        /**
         * @brief   The high-order cell line removal filter for mesh data.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-28
         */
        FITKHighOrderCellFilter* m_highOrderCellFilter{ nullptr };

        /**
         * @brief   The manager of VTK model data.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-30
         */
        Interface::FITKAbaMeshPartVTK* m_meshData{ nullptr };

        /**
         * @brief   The feature data struct for model.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-30
         */
        Interface::FITKMeshFeatureVTK* m_featureMesh{ nullptr };

        /**
         * @brief   The actor for the FE-model part mesh.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-28
         */
        FITKAcousticsVTKGraphActor* m_fActor{ nullptr };

        /**
         * @brief   Current color mode.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-30
         */
        ColorMode m_colorMode = ColorMode::ColorDefault;

        /**
         * @brief   The color map for the mart.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-30
         */
        FITKAcousticsVTKColorMap* m_colorMap{ nullptr };

    };
}   // namespace Exchange

#endif // __FITKACOUSTICSVTKGRAPHOBJECTPART_H__
